import { StackActions, NavigationActions} from 'react-navigation';
let navigator = null;

function setTopLevel(navigatorRef) {
	navigator = navigatorRef;
}

function navigate(routeName, params = {}) {
	navigator.dispatch(
		NavigationActions.navigate({
			name: routeName,
			params: params,
		})
	);
}

function reset(routeName) {
	const resetAction = StackActions.reset({
		index: 0,
		actions: [NavigationActions.navigate({ routeName })],
	});
	navigator.dispatch(resetAction);
}
function goBack(backRoute) {
	const back = NavigationActions.back({
		key: backRoute,
	});
	navigator.dispatch(back);
}

export default {
	navigate,
	reset,
	goBack,
};
